package com.qf.controller;

import com.qf.entity.Cart;
import com.qf.entity.Order;
import com.qf.service.CartService;
import com.qf.service.OrderService;
import com.qf.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

//订单  控制器层
@RestController
@RequestMapping("/OrderController")
public class OrderController {

    @Autowired
    private CartService cartService;

    @Autowired
    private OrderService orderService;

    @Autowired
    private RedisUtils redisUtils;

    @RequestMapping("/addOrder")
    public List<Order> addOrder(HttpServletRequest request){
        System.out.println("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
//        int uId = (int)request.getSession().getAttribute("uId");
        int uId = (int)redisUtils.get("uId");
        List<Cart> cartList = cartService.selByUid(uId);
        for (Cart c:cartList) {
            System.out.println("XXXXXXXXXXXXXXXXXXXXXX================================"+c);
        }
        int i = orderService.addOrder(cartList);
        //通过u_id查询订单
        System.out.println("DDDDDDDDDDDDDDD================"+uId);
        List<Order> ordersList = orderService.selOrderByUId(uId);
        for (Order order:ordersList) {
            System.out.println("NNNNNNNYYYYYYYYYYYYYYYYYYYYYYYYYYNNNN=========="+order);
        }
        return ordersList;
    }
}
